package com.niiwoo.civet.trade.service.local.newRefund.notify.mq;

import java.math.BigDecimal;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.niiwoo.activity.event.dto.request.CreditChangeUsableEventReqDTO;
import com.niiwoo.activity.event.enums.UsableCreditChangeTypeEventEnum;
import com.niiwoo.civet.trade.dao.entity.Project;
import com.niiwoo.civet.trade.service.loan.SpeedLoanDubboService;
import com.niiwoo.civet.trade.service.local.newRefund.notify.dto.RefundNotifyDTO;
import com.niiwoo.civet.trade.service.local.newRefund.notify.enums.RefundNotifyEnum;

/**
 * 活动中心可用额度变更MQ通知 
 * 
 * 触发条件：标的结清
 *  
 * @author: kevin.jia
 * @version 1.0.0
 */
@Component
public class ActivityEventAvaAmountChangeNotify extends MQRefundNotify {

	@Autowired
	private SpeedLoanDubboService speedLoanDubboService;
	
	@Override
	public Object bulidParam(RefundNotifyDTO refundNotifyDTO) {
		Project project = refundNotifyDTO.getProject();
		
		// 获取用户可用额度
        BigDecimal aviAmount = speedLoanDubboService.getSpeedLoanAviAmount(project.getBorrowUserId());

        CreditChangeUsableEventReqDTO creditChangeUsableEventReqDTO = new CreditChangeUsableEventReqDTO();
        creditChangeUsableEventReqDTO.setUserId(project.getBorrowUserId());
		creditChangeUsableEventReqDTO.setCreditChangeTypeEventEnum(UsableCreditChangeTypeEventEnum.REPAYMENT);
        creditChangeUsableEventReqDTO.setAmount(aviAmount);
        creditChangeUsableEventReqDTO.setCreditDate(new Date());
        creditChangeUsableEventReqDTO.setUpdateDate(new Date());
        
        return creditChangeUsableEventReqDTO;
	}
	
	@Override
	public RefundNotifyEnum getType() {
		return RefundNotifyEnum.ACTIVITY_EVENT_AVA_AMOUNT_CHANGE;
	}
}